#include "ds1647.h"

/***************************************************************************************
	DS1647 Start
****************************************************************************************/
void TimeStart()
{
	DS1647_CTRL |= DS1647_WRITE;
	DS1647_SEC &= ~DS1647_OSCSTART;
	DS1647_CTRL &= ~DS1647_WRITE;
}

/***************************************************************************************
	DS1647 Get Time
****************************************************************************************/
void TimeGet(PTMSTRT pTmBuf)
{	
	int i;
	BYTE *p;
	
	DS1647_CTRL |= DS1647_READ;
	
	p = (BYTE *)pTmBuf;
	for(i=0;i<7;i++) p[i] = DS1647_SPEC_REG(i+9);
	
	DS1647_CTRL &= ~DS1647_READ;
}

/***************************************************************************************
	DS1647 Set Time
****************************************************************************************/
void TimeSet(BYTE *pBuf)
{	
	int i;
	
	DS1647_CTRL |= DS1647_WRITE;
	
	DS1647_SEC = (pBuf[5]&0x7F);
	DS1647_MIN = pBuf[4];
	DS1647_HOUR = pBuf[3];
	DS1647_DAY = pBuf[2];
	DS1647_MON = pBuf[1];
	DS1647_YEAR = pBuf[0];
	
	DS1647_CTRL &= ~DS1647_WRITE;
}